package com.dearbinge.opentapi.content.moments;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.moments.BusinessCircleService;
import com.dearbinge.data.pojo.life.LifeMessage;
import com.dearbinge.data.pojo.moments.vo.BusinessCircleVO;
import com.dearbinge.utils.BeanValidator;
import com.dearbinge.utils.ResultMsg;
import com.dearbinge.utils.enums.ResultStatusCodeEnum;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.HashMap;
import java.util.Map;

/**
 * 社交圈控制层
 *
 * @author wes
 * @date 18:22 2019/1/4
 */
@Api(tags = "1.1、社交圈-社交圈动态")
@RestController
@RequestMapping("/moments")
@EnableAutoConfiguration
public class BusinessCircleController extends WebMvcConfigurerAdapter {

    @Autowired
    private BusinessCircleService businessCircleService;



    @ApiOperation(value = "删除动态", notes = "删除动态")
    @ApiImplicitParam(name = "circleId", value = "社交圈id", paramType = "query", required = true)
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public ResultMsg<String> delete(Integer circleId) {
        try {
            Integer dataCode = businessCircleService.delete(circleId);
            if (dataCode > 0) {
                return ResultMsg.ok("删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }


    @ApiOperation(value = "更新点击量", notes = "更新点击量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "clickId", value = "表id", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "1：商品 2：客服 3：分享 4：秀场", paramType = "query", required = true)
    })
    @RequestMapping(value = "/updateClick", method = RequestMethod.GET)
    public ResultMsg<String> updateClick(Integer clickId,Integer type) {
        try {
            Integer dataCode = businessCircleService.updateClick(clickId,type);
            if (dataCode > 0) {
                return ResultMsg.ok("增加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }



//    @ApiOperation(value = "社交圈动态", notes = "社交圈动态")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "loginUser", value = "当前登录用户id", paramType = "query", required = true),
//            @ApiImplicitParam(name = "type", value = "0：全部 1：商品 2：生活", paramType = "query", required = true),
//            @ApiImplicitParam(name = "circleId", value = "社交圈表id 防止查询数据重复", paramType = "query"),
//            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
//            @ApiImplicitParam(name = "size", value = "页面记录数", paramType = "query")})
//    @ApiResponses({
//            @ApiResponse(response = BusinessDynamicVO.class, code = 200, message = "返回结果参数")
//    })
//    @RequestMapping(value = "/listByType", method = RequestMethod.GET)
//    public ResultMsg<Page> listByType(String loginUser, Integer current, Integer size, Integer circleId,Integer type) {
//        try {
//            Page page = businessCircleService.listByType(loginUser, circleId, current, size,type);
//            return ResultMsg.ok(page);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
//    }


    /*————————————————————————废弃的接口 新版本上线后删除————————————————————————————————————*/



    @ApiOperation(value = "单条动态详情(废弃)", notes = "单条动态详情(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "登录的用户id", paramType = "query", required = true),
            @ApiImplicitParam(name = "tableType", value = "类型（0：商品  1：生活）", paramType = "query", required = true),
            @ApiImplicitParam(name = "tableId", value = "表主键id", paramType = "query", required = true)
    })
    @RequestMapping(value = "/getDynamicDetails", method = RequestMethod.GET)
    public ResultMsg<BusinessCircleVO> getDynamicDetails(Integer userId, Integer tableId, Integer tableType) {
        try {
            //校验参数非空
            Map<String, Object> paramMap = new HashMap<String, Object>(16);
            paramMap.put("tableType", tableType);
            paramMap.put("tableId", tableId);
            paramMap.put("userId", userId);
            Map<String, Object> checkParam = BeanValidator.checkParam(paramMap);
            if (!(boolean) checkParam.get(BeanValidator.FLAG)) {
                return ResultMsg.error(ResultStatusCodeEnum.CODE5001.getCode(), checkParam.get("name") + "参数为空");
            }
            return businessCircleService.getDynamicDetails(userId,tableId,tableType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }


    @ApiOperation(value = "社交圈全部动态(废弃)", notes = "社交圈全部动态(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "当前登录用户id", paramType = "query", required = true),
            @ApiImplicitParam(name = "id", value = "社交圈表id 防止数据重复", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面记录数", paramType = "query")})
    @ApiResponses({
            @ApiResponse(response = BusinessCircleVO.class, code = 200, message = "返回结果参数")
    })
    @RequestMapping(value = "/listBusinessCircle", method = RequestMethod.GET)
    public ResultMsg<Page> listBusinessCircle(String userId, Integer current, Integer size, Integer id) {
        try {
            Page page = businessCircleService.listBusinessCircle(userId, id, current, size,0);
            return ResultMsg.ok(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }


    @ApiOperation(value = "社交圈商品动态(废弃)", notes = "社交圈商品动态(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "当前登录用户id", paramType = "query", required = true),
            @ApiImplicitParam(name = "tableId", value = "商品表id", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面记录数", paramType = "query")})
    @ApiResponses({
            @ApiResponse(response = BusinessCircleVO.class, code = 200, message = "返回结果参数")
    })
    @RequestMapping(value = "/listCommodityMessage", method = RequestMethod.GET)
    public ResultMsg<Page> listCommodityMessage(String userId, Integer tableId, Integer current, Integer size) {
        try {
            Page page = businessCircleService.listBusinessCircle(userId, null, current, size,1);
            return ResultMsg.ok(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }


    @ApiOperation(value = "社交圈生活动态(废弃)", notes = "社交圈生活动态(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "当前登录用户id", paramType = "query", required = true),
            @ApiImplicitParam(name = "tableId", value = "生活表id", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面记录数", paramType = "query")})
    @ApiResponses({
            @ApiResponse(response = LifeMessage.class, code = 200, message = "返回结果参数")
    })
    @RequestMapping(value = "/listLifeMessage", method = RequestMethod.GET)
    public ResultMsg<Page> listLifeMessage(String userId, Integer tableId, Integer current, Integer size) {
        try {
            Page page = businessCircleService.listBusinessCircle(userId, null, current, size,2);
            return ResultMsg.ok(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }

    @ApiOperation(value = "个人的全部社交圈(废弃)", notes = "个人的全部社交圈(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面记录数", paramType = "query")})
    @RequestMapping(value = "/listAllMoments", method = RequestMethod.GET)
    public ResultMsg<Page> listAllMoments(String userId, Integer current, Integer size) {
        try {
            Page page = businessCircleService.listAllMomentsByUserId(userId, current, size,0);
            return ResultMsg.ok(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }


}

